package cn.th.service.impl;

import cn.th.dto.AdDto;
import cn.th.entity.Advertising;
import cn.th.entity.Gift;
import cn.th.service.IGiftService;
import cn.th.mapper.GiftMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 礼品表 服务实现类
 * </p>
 *
 * @author cn.th
 * @since 2024-03-30
 */
@Service
public class GiftServiceImpl extends ServiceImpl<GiftMapper, Gift> implements IGiftService {

    @Autowired
    private IGiftService giftService;
    /**
     * 查询礼品表
     * @param page
     * @param pageSize
     * @param school
     * @param name
     * @return
     */
    @Override
    public Map<String, Object> queryGift(int page, int pageSize, String school, String name) {
        LambdaQueryWrapper<Gift> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StringUtils.hasLength(school), Gift::getSchool, school);
        wrapper.like(StringUtils.hasLength(name), Gift::getName, name);

        Page<Gift> page1 = new Page<>(page,pageSize);

        giftService.page(page1,wrapper);

        Map<String, Object> data = new HashMap<>();
        data.put("total",page1.getTotal());
        data.put("rows",page1.getRecords());

        return data;
    }
}
